(********************************************************************)
(*	file:		fCopy.P												*)
(*	version:	.5alpha												*)
(*																	*)
(* Transfer the file whose full pathname is given via appleTalk to 	*)
(* to the entity whose name is also given.							*)
(*																	*)
(* In: 	paramPtr^.params[1]	= name of entity to send the file to	*)
(*		paramPtr^.params[2]	= full pathname of the file to send		*)
(*																	*)
(* ----------------------------------------------------------------	*)
(* By:		Donald Koscheka											*)
(* Date:	26-Apr-88												*)
(* © Copyright 1987, Apple Computer, Inc.							*)
(* All Rights Reserved												*)
(*																	*)
(* ----------------------------------------------------------------	*)
(*						Modification History						*)
(* ----------------------------------------------------------------	*)
(*  Date	   	| By	|	 				Description				*)
(* ----------------------------------------------------------------	*)
(*  13-May-88	| DK	| File Created								*)
(* ----------------------------------------------------------------	*)
(********************************************************************)


(********************************************************************)
(*  Assumes the XCMD has included this file and has named its 		*)
(*	argument "paramPtr".											*)
(********************************************************************)
(********************************************************************
							Build Sequence

pascal -o "{hpo}"fCopy.p.o "{adsp}"fCopy.p
link -m ENTRYPOINT  -rt XFCN=1309 -sn Main=fCopy¶
	"{hpo}"fCopy.p.o¶
	"{libraries}"Interface.o ¶
	"{plibraries}"paslib.o¶
	-o "{hp}"HyperADSPTest
		 
********************************************************************)


{$R-}
{$S fCopy}
UNIT Koscheka;

(*******************************************************************)
INTERFACE 
(*******************************************************************)


Uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, 
	HyperXCmd, AppleTalk, ADSP, adspxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );


(*******************************************************************)
IMPLEMENTATION
(*******************************************************************)


PROCEDURE fCopy( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
	Begin
		fCopy( paramPtr );
	End;
	
	
Procedure fCopy( paramPtr : XCmdPtr );
(*****************************
* Send the file whose name is specified
* to the entity whose name is given...
*
* Note: The connection must be established 
* before using this routine!
*****************************)
VAR
	adsp		: adspPtr;
	error		: OSErr;
	adsp		: ADSPPtr;		{*** Not Used By this routine ***}
	FXRec		: ^^FXRecord;
	eAddr		: AddrBlock;
	cb			: cbPtr;
	startMe		: Str31;
	
{$I XCmdGlue.inc }
{$I XCMDADSP.inc }	

(*****************************  fCopy	*******************************)
BEGIN
	error := noErr;
	adsp := ADSPPtr(RetrieveHandle( GLOBALDSPDATA ));
	
	IF 	(adsp) AND (paramPtr^.params[1] <> NIL) AND 
		(paramPtr^.params[2] <> NIL) THEN
		BEGIN			
			{*** (1) Create the structure for this connection	***}
			HLock( paramPtr^.params[2]);
			
			FXRec := NewHandle( SizeOf( FXRecord ) );
			HLock( Handle(FXrec) );
			WITH FXRec^^ DO
				BEGIN
					Status	FILE_NOT_READY;	
					Fork	NO_FORK;
					FilePtr	:= NIL;	
					ZeroToPas( paramPtr^.params[2]^; Name );
				END;
			HUnlock( Handle(FXRec));
			HUnLock( paramPtr^.params[2]);
			
			{*** (2) Start the transmission off 			***}
			HLock( paramPtr^.params[1] );

			eAddr := NBPGetAddress( paramPtr^.params[1]^ );
			cb := adsp^.ends;
			
			IF LongInt( eAddr ) <> 0 THEN {*** find entity in connection list ***}
				WHILE cb <> NIL DO
					IF (LongInt(cb^.adr)=LongInt(eAddr)) AND (cb^.ccb.state=sOpen) THEN	
						BEGIN
							IF cb^.user = NIL THEN
								cb^.user := Handle( FXRec );
							
							StartMe[0] := 1;
							StartMe[1] := FILE_NOT_READY;
							error := DSPAttention( cb, StartMe, length(StartMe) );
							
						END
					ELSE
						cb := cb^.next;
			
			adsp^.checkPoint := CLOSE_OK;
			HUnlock( Handle(paramPtr^.params[1]) );

		END;
		
	paramPtr^.returnValue := ErrorReturn( error );
END;

end.









